#include "osal_mem.h"
#include "hdf_log.h"
#include "key_config.h"


int32_t ParseKeyConfig(const struct DeviceResourceNode *node, KeyConfig *config)
{
    int32_t ret;
    struct DeviceResourceIface *parser = NULL;
    if (node == NULL || config == NULL) {
        HDF_LOGE("%s: param is null", __func__);
        return HDF_FAILURE;
    }

    parser = DeviceResourceGetIfaceInstance(HDF_CONFIG_SOURCE);
    if (parser == NULL) {
        HDF_LOGE("%s: instance parser failed", __func__);
        return HDF_FAILURE;
    }

    const struct DeviceResourceNode *keyNode = node;
    ret = parser->GetString(keyNode, "keyName", &config->keyName, NULL);
    //CHECK_PARSER_RET(ret, "GetString");
    ret = parser->GetUint8(keyNode, "inputType", &config->devType, 0);
    //CHECK_PARSER_RET(ret, "GetUint8");
    //ret = parser->GetUint16(keyNode, "gpioNum", &config->gpioNum, 0);
    config->gpioNum = 5;
    //CHECK_PARSER_RET(ret, "GetUint16");
    ret = parser->GetUint8(keyNode, "irqFlag", &config->irqFlag, 0);
    //CHECK_PARSER_RET(ret, "GetUint8");
    ret = parser->GetUint32(keyNode, "debounceTime", &config->debounceTime, 0);
    //CHECK_PARSER_RET(ret, "GetUint32");

    HDF_LOGE("keyName = %s, inputType = %d, gpioNum = %d, irqFlag = %d, debounceTime = %d", config->keyName, config->devType, config->gpioNum, config->irqFlag, config->debounceTime);

    return HDF_SUCCESS;
}